<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>教材详情</title>
    <link rel="stylesheet" href="/element-ui/index.css">
    <link rel="stylesheet" href="/element-ui/fonts/element-icons.css">
    <script src="/element-ui/vue.js"></script>
    <script src="/element-ui/index.js"></script>
    <script src="/element-ui/axios.min.js"></script>
    <style>
        body {
            font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '\\5FAE\\8F6F\\96C5\\9ED1', Arial, sans-serif;
            background-color: #f5f6fa;
        }
        #app {
            padding: 20px;
            background-color: #f5f6fa;
        }
        .page-title {
            font-size: 26px;
            font-weight: bold;
            color: #333;
            background: #fff;
            padding: 24px 20px 12px 20px;
            border-bottom: 1px solid #eee;
            margin-bottom: 20px;
            letter-spacing: 2px;
            text-align: center;
            animation: fadeInDown 0.8s ease-out;
            box-shadow: 0 2px 8px rgba(0,0,0,0.05);
            border-radius: 8px;
        }
        @keyframes fadeInDown {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .el-main {
            padding: 20px;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        }
        .el-button {
            transition: all 0.3s ease;
        }
        .el-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        }
        .el-descriptions-item__label {
            font-weight: bold;
            color: #606266;
        }
        .el-descriptions-item__content {
            color: #303133;
        }
        .el-descriptions {
            animation: fadeIn 1s ease-out;
        }
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
    </style>
</head>
<body>
    <div class="page-title">教材详情</div>
    <div id="app">
        <el-container>
            <el-main>
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>教材基本信息</span>
                    </div>
                    <el-descriptions title="" :column="1" border>
                        <el-descriptions-item label="ISBN">{{ book.isbn }}</el-descriptions-item>
                        <el-descriptions-item label="教材名称">{{ book.name }}</el-descriptions-item>
                        <el-descriptions-item label="作者">{{ book.author }}</el-descriptions-item>
                        <el-descriptions-item label="出版社">{{ book.publisher ? book.publisher.name : '' }}</el-descriptions-item>
                        <el-descriptions-item label="价格">{{ book.price }}</el-descriptions-item>
                        <el-descriptions-item label="出版日期">{{ book.publishDate }}</el-descriptions-item>
                        <el-descriptions-item label="版次">{{ book.edition }}</el-descriptions-item>
                        <el-descriptions-item label="描述">{{ book.description }}</el-descriptions-item>
                        <el-descriptions-item label="创建时间">{{ book.createTime ? book.createTime.replace('T', ' ') : '' }}</el-descriptions-item>
                        <el-descriptions-item label="更新时间">{{ book.updateTime ? book.updateTime.replace('T', ' ') : '' }}</el-descriptions-item>
                    </el-descriptions>
                </el-card>
                <div style="margin-top: 30px; text-align: center;">
                    <el-button @click="goBack">返回</el-button>
                </div>
            </el-main>
        </el-container>
    </div>

    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    book: {
                        isbn: '',
                        name: '',
                        author: '',
                        publisher: { name: '' },
                        price: 0,
                        publishDate: '',
                        edition: '',
                        description: '',
                        createTime: '',
                        updateTime: ''
                    }
                }
            },
            created() {
                // 从URL路径中提取ID
                const pathSegments = window.location.pathname.split('/');
                const id = pathSegments[pathSegments.length - 1];
                if (id && !isNaN(id)) { // 确保ID是数字
                    this.fetchBookDetail(id);
                }
            },
            methods: {
                fetchBookDetail(id) {
                    axios.get(`/book/detail/${id}`)
                        .then(response => {
                            this.book = response.data;
                        })
                        .catch(error => {
                            console.error('Error fetching book detail:', error);
                            this.$message.error('获取教材详情失败');
                        });
                },
                goBack() {
                    window.location.href = '/book/list';
                }
            }
        });
    </script>
</body>
</html> 